#include<bits/stdc++.h>
#define IOS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
int jian[114514];
int vv[114514];
int n,m,L,V,T;
int s,a;
int main()
{
    IOS;
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>T;
    while(T--)
    {
        int sum=0;
        cin>>n>>m>>L>>V;
        for(int i=1;i<=n;i++)
        {
            cin>>s>>vv[i]>>a;
        }
        for(int i=1;i<=m;i++)
        {
            cin>>jian[i];
        }
        for(int i=1;i<=n;i++)
        {
            if(vv[i]>V)
            sum++;
        }
        cout<<sum<<" "<<m-1;
        cout<<"\n";
    }
    return 0;
}
